﻿namespace Nomo.UnityCoreModule
{
    /// <summary>
    /// 公共值。
    /// </summary>
    public static class Common
    {
        #region 布尔

        /// <summary>
        /// 应用程序是否正处于运行阶段？
        /// </summary>
        public static bool AppAlive = false;

        /// <summary>
        /// 应用程序是否拥有多个场景？
        /// </summary>
        public static bool AppMultiScene = false;

        /// <summary>
        /// 应用程序是否真正地处于运行状态？
        /// </summary>
        public static bool TrulyPlaying => !UnityEngine.Application.isEditor || UnityEngine.Application.isEditor && UnityEngine.Application.isPlaying;

        #endregion

        #region 数值

        private static float _longTimeUnusedTime = 30F;

        /// <summary>
        /// 界面保持在不活跃状态持续时间超过多少秒之后会被认为是“长时间未激活或处于后台”？
        /// </summary>
        public static float LongTimeUnusedTime { get => _longTimeUnusedTime; set => _longTimeUnusedTime = UnityEngine.Mathf.Max(value, 0F); }

        #endregion

        #region 字符串

        /// <summary>
        /// 日志文件路径。
        /// </summary>
        public static readonly string LogPath = $"{UnityEngine.Application.persistentDataPath}/Log.txt";

        #endregion

        #region 类型

        /// <summary>
        /// <see cref="System.Void"/> 类型。
        /// </summary>
        public static readonly System.Type TypeOfVoid = typeof(void);

        /// <summary>
        /// <see cref="System.Collections.IEnumerator"/> 类型。
        /// </summary>
        public static readonly System.Type TypeOfIEnumerator = typeof(System.Collections.IEnumerator);

        #endregion

        #region 资源包

        private static UnityEngine.AssetBundle _commonAudioAssetBundle;

        /// <summary>
        /// 公共音频资源包。
        /// </summary>
        public static UnityEngine.AssetBundle CommonAudioAssetBundle
        {
            get => _commonAudioAssetBundle;
            set
            {
                _commonAudioAssetBundle.UnloadSafely();
                _commonAudioAssetBundle = value;
            }
        }

        private static UnityEngine.AssetBundle _commonJsonAssetBundle;

        /// <summary>
        /// 公共 JSON 配置资源包。
        /// </summary>
        public static UnityEngine.AssetBundle CommonJsonAssetBundle
        {
            get => _commonJsonAssetBundle;
            set
            {
                _commonJsonAssetBundle.UnloadSafely();
                _commonJsonAssetBundle = value;
            }
        }

        private static UnityEngine.AssetBundle _commonTextureAssetBundle;

        /// <summary>
        /// 公共纹理资源包。
        /// </summary>
        public static UnityEngine.AssetBundle CommonTextureAssetBundle
        {
            get => _commonTextureAssetBundle;
            set
            {
                _commonTextureAssetBundle.UnloadSafely();
                _commonTextureAssetBundle = value;
            }
        }

        #endregion
    }
}
